package com.kfm.am.stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Demo03 {

    public static void main(String[] args) {
        // 有一个员工类 Employee ,里面有name、age和salary字段。请通过 Stream 对多个Employee对象按salary排序,
        // 然后取前3个输出。
        // sorted(比较器) 中间方法 Stream流  limit(n) 0-n  limit 2, 2 forEach()
        List<Employee> employees = new ArrayList<>();
        Employee zs = new Employee("张三", 23, 8000.5);
        Employee ls = new Employee("李四", 24, 8765);
        Employee ww = new Employee("王五", 22, 7638.5);
        Employee sl = new Employee("孙六", 21, 9000.5);
        Collections.addAll(employees, zs, ls, ww, sl);
        // 升序
        employees.stream().sorted((e, e1) -> Double.compare( e1.getSalary(), e.getSalary())).limit(3).forEach(e -> System.out.println(e));

    }
}
